using System;
using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Services;
using Headspring.Training.Domain.Services.Impl;
using NUnit.Framework;
using Rhino.Mocks;

namespace Headspring.Training.Domain.UnitTests.Services
{
    [TestFixture]
    public class NotificationSenderTester
    {
        [Test]
        public void ShouldSendEmailNotification()
        {
            MockRepository mocks = new MockRepository();
            WorkOrderNotification workOrderNotification = new WorkOrderNotification();
			Employee employee = new Employee();
			employee.SetAllNotificationPreferencesTo(NotificationType.Email);
        	workOrderNotification.Recipient = employee;

            IEmailSender emailSender = mocks.CreateMock<IEmailSender>();
            emailSender.Send(workOrderNotification);
			IClock clock = new StubbedClock(new DateTime(2000, 1, 1));
            mocks.ReplayAll();

            INotificationSender sender = new NotificationSender(emailSender, null, clock);
            sender.Send(workOrderNotification);

            mocks.VerifyAll();
        }

        [Test]
        public void ShouldSendSMSNotification()
        {
            MockRepository mocks = new MockRepository();
            WorkOrderNotification workOrderNotification = new WorkOrderNotification();
        	Employee employee = new Employee();
			employee.SetAllNotificationPreferencesTo(NotificationType.SMS);
        	workOrderNotification.Recipient = employee;

            ISmsSender smsSender = mocks.CreateMock<ISmsSender>();
            smsSender.Send(workOrderNotification);
        	IClock clock = new StubbedClock(new DateTime(2000, 1, 1));
            mocks.ReplayAll();

            INotificationSender sender = new NotificationSender(null, smsSender, clock);
            sender.Send(workOrderNotification);

            mocks.VerifyAll();
        }

        [Test]
        public void ShouldSendBothNotification()
        {
            MockRepository mocks = new MockRepository();
            WorkOrderNotification workOrderNotification = new WorkOrderNotification();
        	Employee employee = new Employee();
			employee.SetAllNotificationPreferencesTo(NotificationType.Both);
        	workOrderNotification.Recipient = employee;
            IEmailSender emailSender = mocks.CreateMock<IEmailSender>();
            emailSender.Send(workOrderNotification);

            ISmsSender smsSender = mocks.CreateMock<ISmsSender>();
            smsSender.Send(workOrderNotification);
			IClock clock = new StubbedClock(new DateTime(2000, 1, 1));
            mocks.ReplayAll();

            INotificationSender sender = new NotificationSender(emailSender, smsSender, clock);
            sender.Send(workOrderNotification);

            mocks.VerifyAll();
        }

        [Test]
        public void ShouldNotSendNotification()
        {
            MockRepository mocks = new MockRepository();
            WorkOrderNotification workOrderNotification = new WorkOrderNotification();
        	Employee employee = new Employee();
			employee.SetAllNotificationPreferencesTo(NotificationType.None);
        	workOrderNotification.Recipient = employee;
			IClock clock = new StubbedClock(new DateTime(2000, 1, 1));
            mocks.ReplayAll();

            INotificationSender sender = new NotificationSender(null, null, clock);
            sender.Send(workOrderNotification);

            mocks.VerifyAll();
        }
    }
}